<template>
      <div class='readCardjy'>
        <el-button type="primary" @click="btnClicks">读取</el-button>
       
    </div>
</template>
<script>
export default {
    props:['id'],
    name:'read-cardxzx',
    data(){
        return{
           
        }
    },
    created(){
       
    },
    methods:{
        btnClicks(){
            this.openStock();
        },
        openStock(){
            this.$jsonp("http://localhost:8989/api/ReadMsg?waitTime=3",{}).then(data=>{
                let begin_data="data:image/jpeg;base64,";
                let datas={};
                let BirthDate=data.born;
                datas.Born=BirthDate.substring(0,4)+"-"+BirthDate.substring(4,6)+"-"+BirthDate.substring(6);
                datas.labelA=data.name;
                datas.Sex=data.sex;
                datas.mz=data.nation+"族";
                datas.Address=data.address;
                datas.CardNo=data.cardno;
                datas.image=begin_data+data.photobase64;
                var date = new Date();
                let curYear=date .getFullYear(); //获取完整的年份(4位)
                let age=Number(curYear)-Number(BirthDate.substring(0,4));
                age=age.toFixed(0);
                datas.age=age;
                let ids=this.id.split("|");
                for(let i=0;i<ids.length;i++){
                    let id_=ids[i].split(":");
                    console.log("id_====="+id_[0])
                    if(id_[0]!="image"){
                        let data={};
                        let val=datas[id_[0]];
                        data.id=id_[1];
                        data.val=val;
                        
                        this.$emit("input",JSON.stringify(data));
                    }else{
                        //alert(2);
                        this.$post("business","/api/file/fileUploadBase64",{data:data.photobase64,model:"头像",type:"头像",name:"头像"}).then(data=>{
                        
                            let url=data[0].url;
                            console.log("uploadImg==========================");
                            console.log(url);
                            let data_={};
                            data_.id=id_[1];
                            data_.val=url;
                            this.$emit("input",JSON.stringify(data_));
                        });
                    }
                    
                }
            })
            
        }
        
    }
}
</script>